﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Model
{
    public class ConnectionUtil
    {
        public static  string ConnectionString = "Data Source=192.168.0.101;Initial Catalog=SWA;User ID=sa;Password=123456";

        private static ConnectionUtil instance = null;

        private ConnectionUtil()
        {
        }

        public static ConnectionUtil GetInstance()
        {
            if (instance == null)
            {
                instance = new ConnectionUtil();
            }
            return instance;
        }

        public void ExcuteNonQuery(SqlCommand comm)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                comm.Connection = conn;
                comm.ExecuteNonQuery();
                conn.Close();
            }
        }

        public DataSet ExcuteQuery(SqlCommand comm)
        {
            DataSet ds = new DataSet();
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                comm.Connection = conn;
                new SqlDataAdapter(comm).Fill(ds);

                conn.Close();
            }
            return ds;
        }
    }
}
